// 1.导入mockjs
import Mock from 'mockjs'
// 根据自己的需要有时候需要创建一些随机的数据
// Mock.Random.extend({
//   zhiwei: function () {
//     const arr = ['客服', '董事长', '推广经理']
//     return this.pick(arr)
//   }
// })

// 2.使用mock方法来拦截请求
// mock方法的第一个参数字符串是 拦截的请求地址
// mock方法的第二个参数是 拦截的请求形式
// mock方法的第三个参数是一个函数，当拦截请求成功之后，会执行这个函数，并且将函数的返回值
// 作为请求的结果。
Mock.mock('/my/call', 'get', function () {
  var data = Mock.mock({
    'id|10000+1': 1,
    data: [{
      name: '肖晓雯',
      number: 13273356655,
      phot_for: 'https://images.daojia.com/crm/custom/avatar/29ea9badfb4a7000a3184fd0baf79b97.png.1x1.png?x-oss-process=image/resize,s_720/crop,w_540,h_720,g_north'
    },
    {
      name: '刘香香',
      number: 13987679808,
      phot_for: 'https://images.daojia.com/crm/custom/f1d46943377d08d051e4a493b61c5685.jpeg?x-oss-process=image/resize,s_720/crop,w_540,h_720,g_north '
    },
    {
      name: '谷雨',
      number: 13773456829,
      phot_for: 'https://images.daojia.com/crm/custom/2385667b9c927c97eecd130b854e0d4e.jpeg?x-oss-process=image/resize,s_720/crop,w_540,h_720,g_north'
    },
    {
      name: '王美人',
      number: 13773456829,
      phot_for: 'https://images.daojia.com/crm/custom/2385667b9c927c97eecd130b854e0d4e.jpeg?x-oss-process=image/resize,s_720/crop,w_540,h_720,g_north'
    },
    ]
  })
  return data
})
Mock.mock('/my/call/pro', 'get', function () {
  var data = Mock.mock({
    'id|10000+1': 1,
    data: [{
      profession: '月嫂',
      isacive: false,
    },
    {
      profession: '育婴师',
      isacive: false,
    },
    {
      profession: '保洁/清洁',
      isacive: false,
    },
    {
      profession: '保姆',
      isacive: false,
    },
    {
      profession: '早教/托育',
      isacive: false,
    },
    {
      profession: '家装/搬家',
      isacive: false,
    },
    {
      profession: '养老/陪护',
      isacive: false,
    },
    {
      profession: '产康师',
      isacive: false,
    }
    ]
  })
  return data
})
Mock.mock('/my/certificate', 'get', function () {
  var data = Mock.mock({
    'id|10000+1': 1,
    data: [{
      certificate: '月嫂证'
    },
    {
      certificate: '育婴师证'
    },
    {
      certificate: '小儿推拿证'
    },
    {
      certificate: '保姆证'
    },
    {
      certificate: '保育员证'
    }
    ]
  })
  return data
})
Mock.mock('/my/employment', 'get', function () {
  var data = Mock.mock({
    'id|10000+1': 5,
    data: [{
      name: '月嫂',
      company: '长沙中央家政公司',
      photo: 'https://timgsa.baidu.com/timg?image&quality=80&size=b9999_10000&sec=1602915515913&di=4b0b2bbfbf776d55e3e18e786ec420cf&imgtype=0&src=http%3A%2F%2Fimgsrc.baidu.com%2Fforum%2Fw%3D580%2Fsign%3Dabbf8f972d738bd4c421b239918b876c%2F8169ca8065380cd7e02852a7a244ad3459828159.jpg',
      fname: '@cname()',
      timeF: '@now()',
      wage: '6k-9k',
      label: '勤快 认真 3-5年经验'
    },
    {
      name: '育婴师',
      company: '湖南友臣家政公司',
      photo: 'https://timgsa.baidu.com/timg?image&quality=80&size=b9999_10000&sec=1602915506697&di=0de9d82145697bd3e5f722a13e593af7&imgtype=0&src=http%3A%2F%2Fb-ssl.duitang.com%2Fuploads%2Fitem%2F201901%2F17%2F20190117230425_eofqv.thumb.700_0.jpg',
      fname: '@cname()',
      timeF: '@now()',
      wage: '9k-11k'
    },
    {
      name: '月嫂',
      company: '湖南金管有限公司',
      photo: 'https://timgsa.baidu.com/timg?image&quality=80&size=b9999_10000&sec=1602915506693&di=4db79e6c093bcd934c9d84afe25f1e76&imgtype=0&src=http%3A%2F%2Fn.sinaimg.cn%2Fsinacn11%2F600%2Fw700h700%2F20180424%2F514b-fzqvvsa3694420.jpg',
      fname: '@cname()',
      timeF: '@now()',
      wage: '6k-9k'
    },
    {
      name: '保姆',
      company: '长沙发财家政公司',
      photo: 'https://timgsa.baidu.com/timg?image&quality=80&size=b9999_10000&sec=1602915506621&di=accc3f89a7d6d34e7743361a87dd33f0&imgtype=0&src=http%3A%2F%2Fb-ssl.duitang.com%2Fuploads%2Fitem%2F201608%2F29%2F20160829203548_YHJjV.thumb.700_0.jpeg',
      fname: '@cname()',
      timeF: '@now()',
      wage: '6k-8k'
    },
    {
      name: '产康师',
      company: '湖南眉家家政公司',
      photo: 'https://timgsa.baidu.com/timg?image&quality=80&size=b9999_10000&sec=1602915580319&di=2f469d460484ffa1ae9c0f66f8605955&imgtype=0&src=http%3A%2F%2Fpic2.zhimg.com%2F50%2Fv2-37db418f6bbcf45a3d0616b3de4a9321_hd.jpg',
      fname: '@cname()',
      timeF: '@now()',
      wage: '8k-10k'
    }
    ]
  })
  return data
})
Mock.mock('/home/job', 'post', function (option) {
  // console.log(option)
  // const data = getItem('account')
  // // console.log(option)
  // const body = JSON.parse(option.body)
  // body.status = 1
  // body.id = data.list[data.list.length - 1].id + 1

  // data.list.push(body)

  // setItem('account', data)
  getItem('job')
  const data = JSON.parse(option.body)
  // body.status = 1
  // body.id = data.list[data.list.length - 1].id + 1

  // data.push(body)
  setItem('job', data)
  return Mock.mock({
    statua: 200,
    message: '@cword(4,9)',
  })
})
// 封装的是处理本地存储的方法
export const setItem = (key, value) => {
  // 将数组、对象类型的数据转换为 JSON 格式字符串进行存储
  if (typeof value === 'object') {
    value = JSON.stringify(value)
  }
  window.localStorage.setItem(key, value)
}
/**
 * 获取数据
 */
export const getItem = key => {
  // 假设data得到的就是 ''
  const data = window.localStorage.getItem(key)
  try {
    return JSON.parse(data)
  } catch (err) {
    console.log('获取失败', err)
    return err
  }
}
